<?php

require_once ('mysql/dbHelper.php');
require_once 'session/sessionProcessing.php';
require_once 'utility.php';
require_once 'view/mainMenuView.php';
//TABLES************************************************************************

$mainMenuCssClass = "mainMenu";

/**
 * Gets the html displaying the requirements summary for a project
 * @param type $result the mysql result for all of the sensor,sat,req,subtask,edr for a project
 */
function getRequirementsSummaryTable($result, $projectID) {
    $tdClass = "category3";
    $output .= '<table class="width100" cellspacing="1">';
    $output .= '<caption>Requirements</caption>';
    $output .= ' <tr class ="fieldLabel">';
    $output .= '     <td class="' . $tdClass . '">Requirement</td>';
    $output .= '     <td class="' . $tdClass . '">EDR</td>';
    $output .= '     <td class="' . $tdClass . '">Satellite</td>';
    $output .= '     <td class="' . $tdClass . '">Sensor</td>';
    $output .= '     <td class="' . $tdClass . '">Subtask Title</td>';
    $output .= ' </tr>';
    while ($row = mysqli_fetch_assoc($result)) {
        $sensorName = getSensorName($row['sensorID']);
        $satName = getSatelliteName($row['satelliteID']);
        $reqName = getRequirementNameFromID($row['reqID']);
        $edrname = getParameterNameFromEdrID($row['edrID']);
        $subtaskTitle = getSubtaskTitle($row['subtaskID']);
        $output .= ' <tr>';
        $output .= ' <td>' . $reqName . '</a></td>';
        $output .= ' <td>' . $edrname . '</td>';
        $output .= ' <td>' . $satName . '</td>';
        $output .= ' <td>' . $sensorName . '</td>';
        $output .= ' <td>' . $subtaskTitle . '</td>';
    }
    $output .= getCloseTag("table");
}

/**
 * Gets the html table of the non labor related expenses contained in the given result resource.
 * @param type $result the result resource related to a unique projectID from the db (contains 1 or more rows)
 * @param type $projectID
 */
function getNonLaborSummaryTable($nonLabObj, $showLink) {
    $tdClass = "field";
    $output = '<table class="width100" cellspacing="1">';
    $output .= '<caption>Non Labor Expenses</caption>';
    $output .= ' <col width="26%">';
    $output .= ' <tr class="header">';
    $output .= '     <td>Description</td>';
    $output .= '     <td>Type</td>';
    $output .= '     <td>Cost</td>';
    $output .= ' </tr>';
    while ($row = mysqli_fetch_assoc($result)) {
        $type = $row['type'];
        $description = $row['description'];
        $cost = $row['cost'];
        $nonLaborId = $row['nonLaborCostId'];
        $output .= ' <tr class="field">';
        if ($showLink) {
            $output .= ' <td><a class="black" href="mainPage.php?request=project&action=viewNonLaborDetailsRequest?projectId=' . $this->ID . '&nonLaborId=' . $nonLaborId . '">' . $description . '</a></td>';
        } else {
            $output .= ' <td>' . $description . '</td>';
        }
        $output .= ' <td>' . $type . '</td>';
        //$output .= ' <td>' . $description . '</td>';
        $output .= ' <td>' . $cost . '</td>';
        $output .= '</tr>';
    }
    if ($result && $result->num_rows > 0) {
        getHiddenField("nonLaborId", $nonLaborId);
    }
}

/**
 * Returns some notes depending on project status. Usually used to inform user something additional needs to 
 * be done.
 * @param type $projectStatus
 */
function getNotes($projectStatus, $projectId) {
    $output .= ' <tr class ="fieldLabel">';
    $output .= '     <td class="category">Notes</td>';
    $output .= '     <td colspan="8">';

    if (strcmp($projectStatus, "created") == 0) {
        $output .= 'At least 1 task needs to be created for this project';
        $output .= '    </td>';
    } else if (strcmp($projectStatus, "taskSubmit") == 0) {
        $output .= 'At least 1 task does not have a subtask assigned to it';
        $output .= '    </td>';
    } else if (strcmp($projectStatus, "subtaskSubmit") == 0) {
        $output .= 'All tasks have a subtask assigned to it, project is ready to submit';
        $output .= '    </td>';
    }
}

function getProjectForms($projectID, $type) {


    if (strcmp($type, "PI Feedback") === 0) {
        $projectResult = executeSelect("SELECT n.* FROM notes n, project p WHERE p.projectID=$projectID AND p.wbsID=n.wbsId and type='$type'");
        $taskResult = executeSelect("SELECT n.* FROM notes n, task t WHERE t.projectID=$projectID AND t.wbsID=n.wbsId and type='$type'");
        $subtaskResult = executeSelect("SELECT n.* FROM notes n, task t, subtask st WHERE t.projectID=$projectID AND t.taskID=st.taskID AND st.wbsID=n.wbsId and type='$type'");
        getFeedbackForm($projectResult);
        getFeedbackForm($taskResult);
        getFeedbackForm($subtaskResult);
    } else if (strcmp($type, "Reviewer Notes") === 0) {
        
    } else if (strcmp($type, "grading") === 0) {
        $projectResult = executeSelect("SELECT n.* FROM notes n, project p WHERE p.projectID=$projectID AND p.wbsID=n.wbsId and type='$type'");
        getGradingForm($projectResult, $projectID);
    }
}

/**
 * 
 * @param type $result
 * @param type $action
 * @param type $caption
 * @param type showLink
 */
function getFeedbackForm($result, $action = NULL, $caption = NULL, $showLink = NULL) {

    //do not let PIs see reviewer notes
    if ($caption && strcmp($caption, "Reviewer Notes") === 0 && strcmp(getUserRole(), "pi") === 0) {
        return;
    }
    if ($result && $result->num_rows > 0) {
        if ($action) {
            $output .= getFormLinePost("feedbackForm", $action);
        } else {
            $output .= getFormLinePost("feedbackForm", "notesController.php");
        }
        if ($caption) {
            $caption = "<caption>$caption</caption>";
        } else {
            $caption = '<caption>Feedback</caption>';
        }
        $output .= '<table class="width100" cellspacing="1">';
        $output .= '<col width="45%"><col width="12%"><col width="9%"><col width="9%"><col width="9%">';
        $output .= $caption;
        $output .= ' <tr class ="header">';
        $output .= '     <td>Comments</td>';
        $output .= '     <td>Person</td>';
        $output .= '     <td>Date Created</td>';
        $output .= '     <td>Last Updated</td>';
        $output .= '     <td>Status</td>';
        $output .= '     <td>Options</td>';
        $output .= ' </tr>';
        $counter = 0;
        while ($row = mysqli_fetch_array($result)) {
            $status = $row['status'];
            $url = $row['urlLink'];
            $notes = $row['notes'];
            $wbsID = $row['wbsId'];
            $wbsString = getFieldGivenAnID("wbs", "wbsID", $wbsID, "wbsString");
            $personID = $row['personId'];
            $dateCreated = $row['dateCreated'];
            $lastUpdated = $row['lastUpdated'];

            $output .= '<tr class="field">';
//            if (strcmp(getUserRole(), "pi") === 0) {
//                $output .= '<td><a href="' . $url . '" class="black"></a>';
//            } else {
//                $output .= '<td>';
//            }
            if ($showLink) {
                $output .= '<td><a href="' . $url . '" class="black">';
                $output .= "$notes ($wbsString)</a></td>";
            } else {
                $output .= "<td>$notes</td>";
            }
            $output .= '<td>';
            getPersonNameFromID($personID);
            $output .= '</td>';
            $output .= '<td>' . $dateCreated . '</td>';
            $output .= '<td>' . $lastUpdated . '</td>';
            if (strcmp(getUserRole(), "pi") === 0 && strcmp($status, "created") === 0) {
                $output .= '<td class="red">' . $status . '</td>';
            } else {
                $output .= '<td>' . $status . '</td>';
            }
            $output .= '<td>';
            getFeedbackFormOptionButton($status, $counter, $personID);
            getHiddenField('notes' . $counter . '', $row['notes']);
            getHiddenField('wbs' . $counter . '', $row['wbsId']);
            $output .= '</td>';
            $output .= '</tr>';
            $counter++;
        }
        getCloseTag("table");
        getCloseTag("form");
    }
}

function getFeedbackFormOptionButton($status, $counter, $personID) {
    if (strcmp($status, "created") === 0 && strcmp(getUserRole(), "pi") === 0) {
        $buttonName = 'button' . $counter . '';
        getFormInputElement('submit', $buttonName, "100%", "Mark as complete");

        //getFormInputElement('submit', $buttonName, "100%", "Enter Feedback");
    }
//    else if ( strcmp(getUserRole(), "pireviewer") === 0) {
//        $curPersonID = getPersonIDFromUsername(getCurrentUser());
//        if($curPersonID == $personID){
//            $buttonName = 'button' . $counter . '';
//            getFormInputElement('submit', $buttonName, "100%", "Edit Notes");
//        }
//    }
}

/**
 * A form that reviewers and pi s can view to see feedback associated with a project, task, or subtask
 * @param type $projectResult
 * @param type $taskResult
 * @param type $subtaskResult
 * @param type $action
 */
function getFeedbackForms($projectResult, $taskResult, $subtaskResult, $action = NULL) {


    if ($action) {
        $output .= getFormLinePost("feedbackForm", $action);
    } else {
        $output .= getFormLinePost("feedbackForm", "notesController.php");
    }
    $output .= '<table class="width100" cellspacing="1">';
    $output .= '<caption>Feedback</caption>';
    $output .= ' <tr class ="header">';
    $output .= '     <td>Comments</td>';
    $output .= '     <td>Person</td>';
    $output .= '     <td>Date Created</td>';
    $output .= '     <td>Last Updated</td>';
    $output .= '     <td>Status</td>';
    $output .= '     <td>Change Status</td>';
    $output .= ' </tr>';

    $counter = 0;
    if ($projectResult) {
        while ($row = mysqli_fetch_array($projectResult)) {
            $status = $row['status'];
            $url = $row['urlLink'];
            $notes = $row['notes'];
            $wbsID = $row['wbsId'];
            $personID = $row['personId'];
            $dateCreated = $row['dateCreated'];
            $lastUpdated = $row['lastUpdated'];

            $output .= '<tr class="field">';
            $output .= '<td><a href="' . $url . '" class="black">';
            $output .= "$notes ($wbsID)";
            $output .= '</td>';
            $output .= '<td>';
            getPersonNameFromID($personID);
            $output .= '</td>';
            $output .= '<td>' . $dateCreated . '</td>';
            $output .= '<td>' . $lastUpdated . '</td>';
            $output .= '<td>' . $status . '</td>';
            $output .= '<td>';
            if (strcmp($status, "created") === 0 && strcmp(getUserRole(), "pi") === 0) {
                $buttonName = 'button' . $counter . '';
                getFormInputElement('submit', $buttonName, "100%", "Mark as complete");
                //getFormInputElement('submit', $buttonName, "100%", "Enter Feedback");
            }
            getHiddenField('notes' . $counter . '', $row['notes']);
            getHiddenField('wbs' . $counter . '', $row['wbsId']);
            $output .= '</td>';
            $output .= '</tr>';
            $counter++;
        }
    }
    if ($taskResult) {
        while ($row = mysqli_fetch_array($taskResult)) {
            $status = $row['status'];
            $url = $row['urlLink'];
            $notes = $row['notes'];
            $wbsID = $row['wbsId'];
            $personID = $row['personId'];
            $dateCreated = $row['dateCreated'];
            $lastUpdated = $row['lastUpdated'];

            $output .= '<tr class="field">';
            $output .= '<td><a href="' . $url . '" class="black">';
            $output .= "$notes ($wbsID)";
            $output .= '</td>';
            $output .= '<td>';
            getPersonNameFromID($personID);
            $output .= '</td>';
            $output .= '<td>' . $dateCreated . '</td>';
            $output .= '<td>' . $lastUpdated . '</td>';
            $output .= '<td>' . $status . '</td>';
            $output .= '<td>';
            if (strcmp($status, "created") === 0 && strcmp(getUserRole(), "pi") === 0) {
                $buttonName = 'button' . $counter . '';
                getFormInputElement('submit', $buttonName, "100%", "Mark as complete");
            }
            getHiddenField('notes' . $counter . '', $row['notes']);
            getHiddenField('wbs' . $counter . '', $row['wbsId']);
            $output .= '</td>';
            $output .= '</tr>';
            $counter++;
        }
    }
    if ($subtaskResult) {
        while ($row = mysqli_fetch_array($subtaskResult)) {
            $status = $row['status'];
            $url = $row['urlLink'];
            $notes = $row['notes'];
            $wbsID = $row['wbsId'];
            $personID = $row['personId'];
            $dateCreated = $row['dateCreated'];
            $lastUpdated = $row['lastUpdated'];

            $output .= '<tr class="field">';
            $output .= '<td><a href="' . $url . '" class="black">';
            $output .= "$notes ($wbsID)";
            $output .= '</td>';
            $output .= '<td>';
            getPersonNameFromID($personID);
            $output .= '</td>';
            $output .= '<td>' . $dateCreated . '</td>';
            $output .= '<td>' . $lastUpdated . '</td>';
            $output .= '<td>' . $status . '</td>';
            $output .= '<td>';
            if (strcmp($status, "created") === 0 && strcmp(getUserRole(), "pi") === 0) {
                $buttonName = 'button' . $counter . '';
                getFormInputElement('submit', $buttonName, "100%", "Mark as complete");
            }
            getHiddenField('notes' . $counter . '', $row['notes']);
            getHiddenField('wbs' . $counter . '', $row['wbsId']);
            $output .= '</td>';
            $output .= '</tr>';
            $counter++;
        }
    }
    getCloseTag("table");
    getCloseTag("form");
}

/**
 * Gets the html table of the requirements contained in the given result resource.
 * @param type $result the result resource related to a unique projectID from the db (contains 1 or more rows)
 */
function getRequirementsTable($result, $showLink) {
    $output = "";
    $output .= '<table class="width75Center" cellspacing="1">';
    $output .= '<caption>OPNAV Guidance Letter Prioritized Requirements</caption>';
    $output .= ' <tr class ="fieldLabel">';
    $output .= '     <td class="category2">';
    $output .= '        Description';
    $output .= '     </td>';
    $output .= '     <td class="category2">';
    $output .= '        Priority';
    $output .= '     </td>';
    $output .= '     <td class="category2">';
    $output .= '        Fiscal Year';
    $output .= '     </td>';
    $output .= ' </tr>';
    while ($row = mysqli_fetch_assoc($result)) {
        $reqDescription = $row['description'];
        $reqPriority = $row['priority'];
        $reqId = $row['reqID'];
        $reqFY = $row['fiscalYear'];
        $output .= ' <tr>';
        $output .= ' <td>';
        if (!$showLink) {
            $output .= $reqDescription;
        } else {
            $output .= '<a href="viewReqDetails.php?id=' . $reqId . '">' . $reqDescription . '</a>';
        }
        $output .= ' <td>';
        $output .= $reqPriority;
        $output .= ' </td>';
        $output .= ' <td>';
        $output .= $reqFY;
        $output .= ' </td>';
    }
    $output .= getCloseTag("table");
    return $output;
}

/**
 * Returns a table of satellites and sensors associated with the given parameter.
 * @param type $paramName the parameter name
 * @param type $edrResult all of the edrs for the given parameter
 */
function getSatSensorTable($paramName, $edrResult) {
    $output .= '<table class="width40Center" cellspacing="1">';
    $output .= '<caption>' . $paramName . '</caption>';
    $output .= ' <tr class ="fieldLabel">';
    $output .= '     <td class="category3">';
    $output .= '        Satellite';
    $output .= '     </td>';
    $output .= '     <td class="category3">';
    $output .= '        Sensor';
    $output .= '     </td>';
    $output .= ' </tr>';
    while ($row = mysqli_fetch_assoc($edrResult)) {
        $satName = $row['satName'];
        $sensorName = $row['sensorName'];
        $output .= ' <tr>';
        $output .= ' <td class="col-2">';
        $output .= $satName;
        $output .= ' </td>';
        $output .= ' <td class="col-2">';
        $output .= $sensorName;
        $output .= ' </td>';
    }
    $output .= getCloseTag("table");
}

//FORMS*************************************************************************

function getPerformerTable($typeSubmit, $subtaskLaborResult = NULL) {
    $output .= '  <table class="width100" cellspacing="1" id="performerTable">';
    $output .= '<caption>Subtask Performer List</caption>';
    $output .= '    <tr>';
    $output .= '      <td class ="fieldLabel">Name</td>';
    $output .= '      <td class ="fieldLabel">Hours</td>';
    $output .= '      <td class ="fieldLabel">Rate</td>';
    $output .= '      <td class ="fieldLabel">Cost</td>';
    $output .= '      <td class ="fieldLabel" colspan="2"></td>';
    $output .= '    </tr>';
    if (strcmp($typeSubmit, "edit") == 0) {
        $i = 0;
        while ($row = mysqli_fetch_array($subtaskLaborResult)) {
            $name = $row['personName'];
            $rate = $row['rate'];
            $hours = $row['hours'];
            $output .= '    <tr id="row' . $i . '">';
            $output .= '      <td class ="fieldLabel">';
            $output .= '         <input type="hidden" id="nameField' . $i . '" name="nameField' . $i . '" value="' . $name . '">' . $name . '</td>';
            $output .= '      <td class ="fieldLabel">';
            $output .= '          <input type="hidden" id="hourField' . $i . '" name="hourField' . $i . '" value="' . $hours . '">' . $hours . '</td>';
            $output .= '      <td class ="fieldLabel">';
            $output .= '      <input type="hidden" id="rateField' . $i . '" name="rateField' . $i . '" value="' . $rate . '">' . $rate . '</td>';
            $output .= '      <td class ="fieldLabel">' . ($hours * $rate) . '</td>';
            $output .= '      <td class ="fieldLabel">';
            getFormInputElement("button", $i, NULL, "Edit", "editPerformerRow(this.name)", NULL);
            $output .= '</td>';
            $output .= '      <td class ="fieldLabel">';
            getFormInputElement("button", $i, NULL, "Remove", "removePerformerRow(this.name)", NULL);
            $output .= '</td>';
            $output .= '    </tr>';
            $i++;
        }
    }
    $output .= getCloseTag("table");
}

function getWebmasterFeedbackForm() {
    $output = "";
    $output .= getFormLinePost("satelliteForm", "webmasterSubmit.php");
    $output .= '<table class="width75Center" cellspacing="1">';
    $output .= '<col width="80%"><col width="20%">';
    $output .= '<caption>Send Webmaster Feedback</caption>';
    $output .= ' <tr class ="fieldLabel">';
    $output .= '     <td class="red" colspan="2">Comments</td>';
    $output .= ' </tr>';
    $output .= ' <tr>';
    $output .= '     <td class ="fieldLabel">';
    $output .= getFormInputElement("text", "feedbackTextField", "98%");
    $output .= '     </td>';
    $output .= '     <td class ="fieldLabel">';
    $output .= getFormInputElement('submit', 'submit', "98%", "Send");
    $output .= getHiddenField("user", getCurrentUser());
    $output .= '     </td>';
    $output .= ' </tr>';
    $output .= getCloseTag("table");
    $output .= getCloseTag("form");
    return $output;
}

function getNotesForm($wbsID, $type) {
    getFormLinePost("notesForm", "notesController.php");
    $output .= '<table class="width100" cellspacing="1">';
    $output .= '<col width="80%"><col width="20%">';
    $output .= '<caption>Add Note</caption>';
    $output .= ' <tr class ="fieldLabel">';
    $output .= '     <td colspan="2">Note</td>';
    $output .= ' </tr>';
    $output .= ' <tr>';
    $output .= '     <td class ="fieldLabel">';
    getFormInputElement("text", "noteTextField", "98%");
    $output .= '     </td>';
    $output .= '     <td class ="fieldLabel">';
    getFormInputElement('submit', 'submit', "98%", "Add Note");
    getHiddenField("user", getCurrentUser());
    getHiddenField("wbsID", $wbsID);
    getHiddenField("type", $type);
    $output .= '     </td>';
    $output .= ' </tr>';
    getCloseTag("table");
    getCloseTag("form");
}

//SATELLITE STUFF*****************************************************************************************************************************

/**
 * This is called when the user requests to maintain satellite data in the db. 
 * Options are: new satellite, edit satellite, new spaceAgency, edit spaceAgency
 */
function getSatelliteMaintenanceSelector() {
    $options = array();
    array_push($options, "New Platform Agency");
    array_push($options, "New Platform Programme");
    array_push($options, "New Platform");
    array_push($options, "New Platform Status");
    array_push($options, "Edit Platform Agency");
    array_push($options, "Edit Platform Programme");
    array_push($options, "Edit Platform");
    $output .= '<table class="width20Center" cellspacing="1">';
    $output .= ' <tr class ="fieldLabel">';
    $output .= '     <td class="category">';
    $output .= '        Select an activity to complete';
    $output .= '     </td>';
    $output .= ' </tr>';
    $output .= ' <tr>';
    $output .= '     <td>';
    getDropDownMenu($options, 'satellitesDropdown', NULL, NULL, 'getPlatformMaintenanceForm(this.value)');
    //getGenericDropdownMenu(getSatellites2(), 'satellitesDropdown', '98%', false, 'getEditSatelliteForm(this.value)');
    $output .= '     </td>';
    $output .= ' </tr>';
    getCloseTag("table");
}

function getButtonGrid() {
    $options = array();
    array_push($options, "New Parameter");
    array_push($options, "New EDR");
    array_push($options, "Edit Parameter");
    $output .= '<table class="width40Center" cellspacing="1">';
    $output .= ' <tr class ="fieldLabel">';
    $output .= '     <td class="category">';
    $output .= '        Parameter';
    $output .= '     </td>';
    $output .= ' <td>';
    getFormInputElement('submit', 'newParamButton', '98%', 'New Parameter', 'getMaintenanceForm(this.value)');
    $output .= '</td>';
    $output .= ' <td>';
    getFormInputElement('submit', 'newParamButton', '98%', 'Edit Parameter', 'getMaintenanceForm(this.value)');
    $output .= '</td>';
    $output .= ' </tr>';
    $output .= ' <tr class ="fieldLabel">';
    $output .= '     <td class="category">';
    $output .= '        EDR';
    $output .= '     </td>';
    $output .= ' <td>';
    getFormInputElement('submit', 'newParamButton', '98%', 'New EDR', 'getMaintenanceForm(this.value)');
    $output .= '</td>';
    $output .= ' <td>';
    getFormInputElement('submit', 'newParamButton', '98%', 'Edit EDR', 'getMaintenanceForm(this.value)');
    $output .= '</td>';
    $output .= ' </tr>';
    $output .= ' <tr class ="fieldLabel">';
    $output .= '     <td class="category">';
    $output .= '        Platform';
    $output .= '     </td>';
    $output .= ' <td>';
    getFormInputElement('submit', 'newParamButton', '98%', 'New Platform', 'getMaintenanceForm(this.value)');
    $output .= '</td>';
    $output .= ' <td>';
    getFormInputElement('submit', 'newParamButton', '98%', 'Edit Platform', 'getMaintenanceForm(this.value)');
    $output .= '</td>';
    $output .= ' </tr>';
    $output .= ' <tr class ="fieldLabel">';
    $output .= '     <td class="category">';
    $output .= '        Sensor';
    $output .= '     </td>';
    $output .= ' <td>';
    getFormInputElement('submit', 'newParamButton', '98%', 'New Sensor', 'getMaintenanceForm(this.value)');
    $output .= '</td>';
    $output .= ' <td>';
    getFormInputElement('submit', 'newParamButton', '98%', 'Edit Sensor', 'getMaintenanceForm(this.value)');
    $output .= '</td>';
    $output .= ' </tr>';

    getCloseTag("table");
}

function getParameterMaintenanceSelector() {
    $options = array();
    array_push($options, "New Parameter");
    array_push($options, "New EDR");
    array_push($options, "Edit Parameter");
    $output .= '<table class="width20Center" cellspacing="1">';
    $output .= ' <tr class ="fieldLabel">';
    $output .= '     <td class="category">';
    $output .= '        Select an activity to complete';
    $output .= '     </td>';
    $output .= ' </tr>';
    $output .= ' <tr>';
    $output .= '     <td>';
    getDropDownMenu($options, 'parameterDropdown', NULL, NULL, 'getParameterMaintenanceForm(this.value)');
    //getGenericDropdownMenu(getSatellites2(), 'satellitesDropdown', '98%', false, 'getEditSatelliteForm(this.value)');
    $output .= '     </td>';
    $output .= ' </tr>';
    getCloseTag("table");
}

function getSensorMaintenanceSelector() {
    $options = array();
    array_push($options, "New Sensor");
    array_push($options, "Edit Sensor");
    $output .= '<table class="width20Center" cellspacing="1">';
    $output .= ' <tr class ="fieldLabel">';
    $output .= '     <td class="category">';
    $output .= '        Select an activity to complete';
    $output .= '     </td>';
    $output .= ' </tr>';
    $output .= ' <tr>';
    $output .= '     <td>';
    getDropDownMenu($options, 'satellitesDropdown', NULL, NULL, 'getSensorMaintenanceForm(this.value)');
    //getGenericDropdownMenu(getSatellites2(), 'satellitesDropdown', '98%', false, 'getEditSatelliteForm(this.value)');
    $output .= '     </td>';
    $output .= ' </tr>';
    getCloseTag("table");
}

/**
 * This is called when a used wishes to edit an existing satellite. It is just a dropdown of existing satellites. 
 * When a satellite is selected a edit satellite form is returned for the selected satellite.
 */
function getPlatformSelector() {
    getFormLinePostWithOnSubmit("satelliteForm", "editDBSubmit.php", "validateSatellite(this)");
    $output .= '<table class="width20Center" cellspacing="1">';
    $output .= '<caption>Platform Select</caption>';
    $output .= ' <tr class ="fieldLabel">';
    $output .= '     <td class="category">';
    $output .= '        Select a Satellite to Modify';
    $output .= '     </td>';
    $output .= ' </tr>';
    $output .= ' <tr>';
    $output .= '     <td>';
    getGenericDropdownMenu(getSatellites2(), 'satellitesDropdown', '98%', false, 'getEditSatelliteForm(this.value)');
    $output .= '     </td>';
    $output .= ' </tr>';
    getCloseTag("table");
    getCloseTag("form");
}

function getParameterSelector() {
    getFormLinePostWithOnSubmit("satelliteForm", "editDBSubmit.php", "validateParameter(this)");
    $output .= '<table class="width20Center" cellspacing="1">';
    $output .= '<caption>Parameter Select</caption>';
    $output .= ' <tr class ="fieldLabel">';
    $output .= '     <td class="category">';
    $output .= '        Select a Parameter to Modify';
    $output .= '     </td>';
    $output .= ' </tr>';
    $output .= ' <tr>';
    $output .= '     <td>';
    getGenericDropdownMenu(getParameters(), 'sensorDropdown', '98%', false, 'getEditParameterForm(this.value)');
    $output .= '     </td>';
    $output .= ' </tr>';
    getCloseTag("table");
    getCloseTag("form");
}

function getSensorSelector() {
    getFormLinePostWithOnSubmit("satelliteForm", "editDBSubmit.php", "validateSatellite(this)");
    $output .= '<table class="width20Center" cellspacing="1">';
    $output .= '<caption>Sensor Select</caption>';
    $output .= ' <tr class ="fieldLabel">';
    $output .= '     <td class="category">';
    $output .= '        Select a Sensor to Modify';
    $output .= '     </td>';
    $output .= ' </tr>';
    $output .= ' <tr>';
    $output .= '     <td>';
    getGenericDropdownMenu(getSensors(), 'sensorDropdown', '98%', false, 'getEditSensorForm(this.value)');
    $output .= '     </td>';
    $output .= ' </tr>';
    getCloseTag("table");
    getCloseTag("form");
}

function getProgrammeSelector() {
    getFormLinePostWithOnSubmit("satelliteForm", "editDBSubmit.php", "validateSatellite(this)");
    $output .= '<table class="width20Center" cellspacing="1">';
    $output .= ' <tr class ="fieldLabel">';
    $output .= '     <td class="category">';
    $output .= '        Select a Programme to Modify';
    $output .= '     </td>';
    $output .= ' </tr>';
    $output .= ' <tr>';
    $output .= '     <td>';
    getGenericDropdownMenu(getProgrammes(), 'programmeDropdown', '98%', false, 'getEditProgrammeForm(this.value)');
    $output .= '     </td>';
    $output .= ' </tr>';
    getCloseTag("table");
    getCloseTag("form");
}

/**
 * This is called when a used wishes to edit an existing agency. It is just a dropdown of existing agencies. 
 * When an agency is selected a edit agency form is returned for the selected agency.
 */
function getAgencySelector() {
    getFormLinePostWithOnSubmit("satelliteForm", "editDBSubmit.php", "validateSatellite(this)");
    $output .= '<table class="width20Center" cellspacing="1">';
    $output .= ' <tr class ="fieldLabel">';
    $output .= '     <td class="category">';
    $output .= '        Select an Agency to Modify';
    $output .= '     </td>';
    $output .= ' </tr>';
    $output .= ' <tr>';
//    $output .= '     <td>';
//    getFormInputElement('button', 'createSatButton', '98%', "Create Satellite", 'getNewSatelliteForm()');
//    $output .= '     </td>';
    $output .= '     <td>';
    getGenericDropdownMenu(getAgencies(), 'agencyDropdown', '98%', false, 'getEditAgencyForm(this.value)');
    $output .= '     </td>';
    $output .= ' </tr>';
    getCloseTag("table");
    getCloseTag("form");
}

function getNewStatusForm($result = NULL) {
    $row = NULL;
    if ($result) {
        $row = mysqli_fetch_array($result);
    }
    getFormLinePostWithOnSubmit("satelliteForm", "editDBSubmit.php", "validateStatus(this)");
    $output .= '<table class="width20Center" cellspacing="1">';
    if ($row) {
        $output .= '<caption>Edit Current Status</caption>';
    } else {
        $output .= '<caption>Create New Status</caption>';
    }
    $output .= ' <tr class ="fieldLabel">';
    $output .= '     <td class="category">';
    $output .= '        Status Name';
    $output .= '     </td>';
    $output .= ' </tr>';

    //divs
    $output .= ' <tr>';
    $output .= '     <td class ="fieldLabel">';
    $output .= '        <div class="container300px" id="statusInfoBox">';
    getFormInputElement('text', 'statusTextField');
    $output .= '        </div>';
    $output .= '     </td>';
    $output .= ' </tr>';
    $output .= ' <tr>';
    $output .= '     <td class ="fieldLabel">';
    if ($row) {
        getFormInputElement('submit', 'submit', NULL, "Update Status");
    } else {
        getFormInputElement('submit', 'submit', NULL, "Create Status");
    }
    $output .= '     </td>';
    $output .= ' </tr>';
    getCloseTag("table");
    getCloseTag("form");
}

/**
 * This is returned blank for a new agency and populated for editing an agency
 * @param type $result the mysql result for an agency wishing to be modified
 */
function getPlatformAgencyForm($result = NULL) {
    $row = NULL;
    if ($result) {
        $row = mysqli_fetch_array($result);
    }
    getFormLinePostWithOnSubmit("satelliteForm", "editDBSubmit.php", "validateAgency(this)");
    $output .= '<table class="width20Center" cellspacing="1">';
    if ($row) {
        $output .= '<caption>Edit Platform Agency</caption>';
    } else {
        $output .= '<caption>Create Platform Agency</caption>';
    }
    $output .= ' <tr class ="fieldLabel">';
    $output .= '     <td class="category">';
    $output .= '        Platform Agency Information';
    $output .= '     </td>';
    $output .= ' </tr>';

    //divs
    $output .= ' <tr>';
    $output .= '     <td class ="fieldLabel">';
    $output .= '        <div class="container300px" id="agencyInfoBox">';
    getPlatformAgencyFields($row);
    $output .= '        </div>';
    $output .= '     </td>';
    $output .= ' </tr>';
    $output .= ' <tr>';
    $output .= '     <td class ="fieldLabel">';
    if ($row) {
        getFormInputElement('submit', 'submit', NULL, "Update Agency");
        $agencyID = $row['spaceAgencyID'];
        getHiddenField('spaceAgencyID', $agencyID);
    } else {
        getFormInputElement('submit', 'submit', NULL, "Create Agency");
    }
    $output .= '     </td>';
    $output .= ' </tr>';
    getCloseTag("table");
    getCloseTag("form");
}

/**
 * The fields that are part of the Platform Agency Form - they go inside of the div
 * @param type $row If not NULL then the fields are populated with the data in the $row
 */
function getPlatformAgencyFields($row) {
    if ($row) {
        $acronym = $row['acronym'];
        $fullName = $row['name'];
        $country = $row['country'];
        $spaceAgencyID = $row['spaceAgencyID'];
        getHiddenField('spaceAgencyID', $spaceAgencyID);
    }
    $output .= 'Acronym <br>';
    if ($row) {
        getFormInputElement('text', 'acronymTextField', '98%', $acronym);
    } else {
        getFormInputElement('text', 'acronymTextField', '98%');
    }
    $output .= '<br><br>';
    $output .= 'Full Name <br>';
    if ($row) {
        getFormInputElement('text', 'nameTextField', '98%', $fullName);
    } else {
        getFormInputElement('text', 'nameTextField', '98%');
    }
    $output .= '<br><br>';
    $output .= 'Country <br>';
    if ($row) {
        getFormInputElement('text', 'countryTextField', '98%', $country);
    } else {
        getFormInputElement('text', 'countryTextField', '98%');
    }
    $output .= '<br><br>';
}

/**
 * This returns a programme form (empty or populated for the given $result)
 * @param type $result the mysql result for a programme wishing to be modified
 * @param type $result
 */
function getProgrammeForm($result = NULL) {
    $row = NULL;
    if ($result) {
        $row = mysqli_fetch_array($result);
    }
    getFormLinePostWithOnSubmit("programmeForm", "editDBSubmit.php", "validateProgramme(this)");
    $output .= '<table class="width75Center" cellspacing="1">';
    if ($row) {
        $output .= '<caption>Edit Programme</caption>';
    } else {
        $output .= '<caption>Create Programme</caption>';
    }

    //2 row (header, divs) 4 columns (each column has a div)
    //Row 1 Header
    $output .= ' <tr class ="fieldLabel">';
    $output .= '     <td class="category">';
    $output .= '        Programme Name Information';
    $output .= '     </td>';
    $output .= '     <td class="category">';
    $output .= '        Programme Dates';
    $output .= '     </td>';
//    $output .= '     <td class="category">';
//    $output .= '        Satellite Agencies';
//    $output .= '     </td>';
    $output .= '     <td class="category">';
    $output .= '        Programme Agencies';
    $output .= '     </td>';
    $output .= ' </tr>';

    //divs
    $output .= ' <tr>';
    $output .= '     <td class ="fieldLabel">';
    $output .= '        <div class="container300px" id="satInfoBox">';
    getNewProgrammeInfoFields($row);
    $output .= '        </div>';
    $output .= '     </td>';
    $output .= '     <td class ="fieldLabel">';
    $output .= '        <div class="container250px" id="satDateBox">';
    getNewProgrammeDateFields($row);
    $output .= '        </div>';
    $output .= '     </td>';
    $output .= '     <td class ="fieldLabel">';
    $output .= '        <div class="container350pxScrolls" id="satSensorBox">';
    getProgrammeAgencyFields($row);
    $output .= '        </div>';
    $output .= '     </td>';
    $output .= ' </tr>';

    if ($row) {
        $programmeID = $row['satelliteProgrammeID'];
        getHiddenField("satelliteProgrammeID", $programmeID);
    }
    $output .= '<tr><td class="fieldLabel" colspan="4">';
    if ($result) {
        getFormInputElement("submit", "submit", NULL, "Update Programme");
    } else {
        getFormInputElement("submit", "submit", NULL, "Create Programme");
    }
    $output .= '</td></tr>';
    getCloseTag("table");
    getCloseTag("form");
}

function getSensorForm($result = NULL) {
    $row = NULL;
    if ($result) {
        $row = mysqli_fetch_array($result);
    }
    getFormLinePostWithOnSubmit("satelliteForm", "editDBSubmit.php", "validateSensor(this)");
    $output .= '<table class="width20Center" cellspacing="1">';
    if ($row) {
        $output .= '<caption>Edit Sensor</caption>';
    } else {
        $output .= '<caption>Create Sensor</caption>';
    }

    //2 row (header, divs) 4 columns (each column has a div)
    //Row 1 Header
    $output .= ' <tr class ="fieldLabel">';
    $output .= '     <td class="category">';
    $output .= '        Sensor Information';
    $output .= '     </td>';
    $output .= ' </tr>';

    //divs
    $output .= ' <tr>';
    $output .= '     <td class ="fieldLabel">';
    $output .= '        <div class="container300px" id="satInfoBox">';
    getNewSensorInfoFields($row);
    $output .= '        </div>';
    $output .= '     </td>';
    $output .= ' </tr>';

    if ($row) {
        $sensorID = $row['sensorID'];
        getHiddenField("sensorID", $sensorID);
    }

    $output .= '<tr><td class="fieldLabel" colspan="4">';
    if ($result) {
        getFormInputElement("submit", "submit", NULL, "Update Sensor");
    } else {
        getFormInputElement("submit", "submit", NULL, "Create Sensor");
    }
    $output .= '</td></tr>';
    getCloseTag("table");
    getCloseTag("form");
}

/**
 * This is returned blank for a new platform and populated for editing a platform
 * @param type $result the mysql result for a platform wishing to be modified
 */
function getSatelliteForm($result = NULL) {
    $row = NULL;
    if ($result) {
        $row = mysqli_fetch_array($result);
    }
    getFormLinePostWithOnSubmit("satelliteForm", "editDBSubmit.php", "validateSatellite(this)");
    $output .= '<table class="width75Center" cellspacing="1">';
    if ($row) {
        $output .= '<caption>Edit Platform</caption>';
    } else {
        $output .= '<caption>Create Platform</caption>';
    }

    //2 row (header, divs) 4 columns (each column has a div)
    //Row 1 Header
    $output .= ' <tr class ="fieldLabel">';
    $output .= '     <td class="category">';
    $output .= '        Satellite Name Information';
    $output .= '     </td>';
    $output .= '     <td class="category">';
    $output .= '        Satellite Dates';
    $output .= '     </td>';
//    $output .= '     <td class="category">';
//    $output .= '        Satellite Agencies';
//    $output .= '     </td>';
    $output .= '     <td class="category">';
    $output .= '        Satellite Sensor(s)';
    $output .= '     </td>';
    $output .= ' </tr>';

    //divs
    $output .= ' <tr>';
    $output .= '     <td class ="fieldLabel">';
    $output .= '        <div class="container300px" id="satInfoBox">';
    getNewSatelliteInfoFields($row);
    $output .= '        </div>';
    $output .= '     </td>';
    $output .= '     <td class ="fieldLabel">';
    $output .= '        <div class="container250px" id="satDateBox">';
    getNewSatelliteDateFields($row);
    $output .= '        </div>';
    $output .= '     </td>';
//    $output .= '     <td class ="fieldLabel">';
//    $output .= '        <div class="container3" id="agencyBox">';
//    getNewSatelliteAgencyFields($row);
//    $output .= '        </div>';
//    $output .= '     </td>';
    $output .= '     <td class ="fieldLabel">';
    $output .= '        <div class="container350pxScrolls" id="satSensorBox">';
    getNewSatelliteSensorFields($row);
    $output .= '        </div>';
    $output .= '     </td>';
    $output .= ' </tr>';

    if ($row) {
        $satID = $row['satelliteID'];
        getHiddenField("satID", $satID);
    }
    //if(strcmp($type, "create")===0){
    $output .= '<tr><td class="fieldLabel" colspan="4">';
    if ($result) {
        getFormInputElement("submit", "submit", NULL, "Update Satellite");
    } else {
        getFormInputElement("submit", "submit", NULL, "Create Satellite");
    }
    $output .= '</td></tr>';
    //}
    getCloseTag("table");
    getCloseTag("form");
//    $array = array();
//    array_push($array, "satLaunchDatepicker");
//    getDatepickerScript($array);
}

/**
 * The fields that are part of the Platform Form - they go inside of the div
 * @param type $row If not NULL then the fields are populated with the data in the $row
 */
function getNewSatelliteSensorFields($row = NULL) {

    if ($row) {
        $satID = $row['satelliteID'];
        $launchDate = $row['launchDate'];
        $eol = $row['eol'];
    }
    //3 fields (Acronym, Full Name, Programme) 
    //$output .= 'Launch Date <br>';
    if ($row) {
        //getSensorsFromSat($satID);
        getSensorAcronymsOnSat($satID);
    } else {
        getSensorCheckboxList();
    }
}

/**
 * The fields that are part of the Programme Form - they go inside of the div 
 * @param type $row If not NULL then the fields are populated with the data in the $row
 */
function getProgrammeAgencyFields($row = NULL) {

    if ($row) {
        $programmeID = $row['satelliteProgrammeID'];
    }
    if ($row) {
        getProgrammeAgencies($programmeID);
    } else {
        getAgencyCheckboxList();
    }
}

/**
 * The fields that are part of the Platform or sensor Form - they go inside of the div
 * @param type $row If not NULL then the fields are populated with the data in the $row
 */
function getAgencyFields($row = NULL) {

    //3 fields (Acronym, Full Name, Programme) 
    $output .= 'Space Agency <br>';
    getGenericDropdownMenu(getSpaceAgencies(), 'agencyDropdown', '98%', false, NULL, "agencyDropdown", NULL, NULL, "Select an agency then click add.");
    $output .= '   ';
    getFormInputElement('button', 'addAgencyButton', NULL, "Add Agency", "addAgencyRow()", "addAgencyButton");
    $output .= '<br><br>';
    $output .= 'Agency List <br>';
    $output .= '  <table class="width100" cellspacing="1" id="agencyTable">';
    $output .= '    <tr>';
    $output .= '      <td class ="fieldLabel">Name</td>';
    $output .= '      <td class ="fieldLabel"></td>';
    $output .= '    </tr>';
    if ($row) {
        $satProgramID = $row['satelliteProgrammeID'];
        getAgenciesForEditSatProgram($satProgramID);
        //iterate through the result and add the current agencies
        //getFormInputElement('text', 'nameTextField', '98%', $fullName);
    } else {
        //getFormInputElement('text', 'nameTextField', '98%');
    }
    getCloseTag("table");
}

/**
 * Not yet used
 * @param type $satProgramID
 */
function getAgenciesForEditSatProgram($satProgramID) {
    $agencyResult = executeSelect("SELECT sa.spaceAgencyID, sa.acronym FROM spaceagency sa, satelliteprogrammespaceagencymap map 
                                   WHERE map.satelliteProgramID=$satProgramID AND map.spaceAgencyID=sa.spaceAgencyID");
    $i = 0;
    while ($row = mysqli_fetch_array($agencyResult)) {
        $agency = $row['acronym'];

        $output .= '        <tr id="row' . $i . '">';
        $output .= '     <td class="col-2">';
        $output .= '       <input type="hidden" id="agency' . $i . '" name="agency' . $i . '" value="' . $agency . '">' . $agency . '';
        $output .= '     </td>';
        $output .= '     <td class="col-2">';
        //$output .= getButtonWithNameAndAction();
        getFormInputElement("button", "$i", NULL, 'Remove', "removeAgencyRow(this.name)", NULL);
        $output .= '</td>';
        $output .= '        </tr>';
    }
}

/**
 * The fields that are part of the Platform Form - they go inside of the div
 * @param type $row If not NULL then the fields are populated with the data in the $row
 */
function getNewSatelliteDateFields($row = NULL) {

    if ($row) {
        $satID = $row['satelliteID'];
        $launchDate = $row['launchDate'];
        $eol = $row['eol'];
        $statusID = $row['hardwareStatusID'];
    }
    //3 fields (Acronym, Full Name, Programme) 
    $output .= 'Launch Date <br>';
    if ($row) {
        getFormInputElement('text', 'satLaunchDatepicker', '97%', $launchDate, null, "satLaunchDatepicker");
    } else {
        getFormInputElement('text', 'satLaunchDatepicker', '97%', NULL, NULL, "satLaunchDatepicker");
    }
    $output .= '<br><br>';
    $output .= 'End Of Life (Year) <br>';
    if ($row) {
        getFormInputElement('text', 'eolTextField', '97%', $eol);
    } else {
        getFormInputElement('text', 'eolTextField', '97%');
    }
    $output .= '<br><br>';
    $output .= 'Status: ';
    if ($row) {
        getGenericDropdownMenu(getHardwareStatusSelections(), 'statusDropdown', '98%', false, null, null, $statusID, NULL, "Edit the programme this satellite belongs to");
    } else {
        //$output .= '<a href=\"#\" title="Select a status or click here to create a new status">Status:</a> ';
        getGenericDropdownMenu(getHardwareStatusSelections(), 'statusDropdown', '98%', false);
    }
}

/**
 * The fields that are part of the Programme Form - they go inside of the div
 * @param type $row If not NULL then the fields are populated with the data in the $row
 */
function getNewProgrammeDateFields($row = NULL) {

    if ($row) {
        $programmeID = $row['satelliteProgrammeID'];
        $launchDate = $row['firstLaunch'];
        $eol = $row['eol'];
    }
    //3 fields (Acronym, Full Name, Programme) 
    $output .= 'Launch Date <br>';
    if ($row) {
        getFormInputElement('text', 'satLaunchDatepicker', '97%', $launchDate, null, "satLaunchDatepicker");
    } else {
        getFormInputElement('text', 'satLaunchDatepicker', '97%', NULL, NULL, "satLaunchDatepicker");
    }
    $output .= '<br><br>';
    $output .= 'End Of Life (Year) <br>';
    if ($row) {
        getFormInputElement('text', 'eolTextField', '97%', $eol);
    } else {
        getFormInputElement('text', 'eolTextField', '97%');
    }
}

function getNewSensorInfoFields($row = NULL) {

    if ($row) {
        $acronym = $row['acronym'];
        $fullName = $row['name'];
        $agencyID = $row['spaceAgencyID'];
        $startDate = $row['startDate'];
        $endDate = $row['endDate'];
    }
    //3 fields (Acronym, Full Name, Programme) 
    $output .= 'Acronym <br>';
    if ($row) {
        getFormInputElement('text', 'acronymTextField', '98%', $acronym);
    } else {
        getFormInputElement('text', 'acronymTextField', '98%');
    }
    $output .= '<br><br>';
    $output .= 'Full Name <br>';
    if ($row) {
        getFormInputElement('text', 'nameTextField', '98%', $fullName);
    } else {
        getFormInputElement('text', 'nameTextField', '98%');
    }
    $output .= '<br><br>';
    $output .= 'Start Usage (Year:YYYY) <br>';
    if ($row) {
        getFormInputElement('text', 'startTextField', '50%', $startDate);
    } else {
        getFormInputElement('text', 'startTextField', '50%');
    }
    $output .= '<br><br>';
    $output .= 'End Usage (Year:YYYY) <br>';
    if ($row) {
        getFormInputElement('text', 'eolTextField', '50%', $endDate);
    } else {
        getFormInputElement('text', 'eolTextField', '50%');
    }
    $output .= '<br><br>';
    $output .= 'Agency <br>';
    if ($row) {
        getGenericDropdownMenu(getAgencies(), 'agencyDropdown', '98%', false, null, null, $agencyID, NULL, "Edit the agency this sensor belongs to");
    } else {
        //$output .= '<a href="#" title="Select a programme or click here to create a new program" onclick="getPlatformMaintenanceForm("New Platform Program")">Programme:</a> ';
        getGenericDropdownMenu(getAgencies(), 'agencyDropdown', '98%', false);
    }
}

/**
 * The fields that are part of the Platform Form - they go inside of the div
 * @param type $row If not NULL then the fields are populated with the data in the $row
 */
function getNewSatelliteInfoFields($row = NULL) {

    if ($row) {
        $satID = $row['satelliteID'];
        $acronym = $row['acronym'];
        $fullName = $row['name'];
        $programmeID = $row['satelliteProgrammeID']; //need to make sure the query names this programme
    }
    //3 fields (Acronym, Full Name, Programme) 
    $output .= 'Acronym <br>';
    if ($row) {
        getFormInputElement('text', 'acronymTextField', '98%', $acronym);
    } else {
        getFormInputElement('text', 'acronymTextField', '98%');
    }
    $output .= '<br><br>';
    $output .= 'Full Name <br>';
    if ($row) {
        getFormInputElement('text', 'nameTextField', '98%', $fullName);
    } else {
        getFormInputElement('text', 'nameTextField', '98%');
    }
    $output .= '<br><br>';
    $output .= 'Programme: ';
    if ($row) {
        getGenericDropdownMenu(getSatProgrammes(), 'programmeDropdown', '98%', false, null, null, $programmeID, NULL, "Edit the programme this satellite belongs to");
    } else {
        //$output .= '<a href="#" title="Select a programme or click here to create a new program" onclick="getPlatformMaintenanceForm("New Platform Program")">Programme:</a> ';
        getGenericDropdownMenu(getSatProgrammes(), 'programmeDropdown', '98%', false);
    }
}

/**
 * The fields that are part of the Programme Form - they go inside of the div
 * @param type $row If not NULL then the fields are populated with the data in the $row
 */
function getNewProgrammeInfoFields($row = NULL) {

    if ($row) {
        $programmeID = $row['satelliteProgrammeID'];
        $acronym = $row['acronym'];
        $fullName = $row['name'];
    }
    //3 fields (Acronym, Full Name, Programme) 
    $output .= 'Acronym <br>';
    if ($row) {
        getFormInputElement('text', 'acronymTextField', '98%', $acronym);
    } else {
        getFormInputElement('text', 'acronymTextField', '98%');
    }
    $output .= '<br><br>';
    $output .= 'Full Name <br>';
    if ($row) {
        getFormInputElement('text', 'nameTextField', '98%', $fullName);
    } else {
        getFormInputElement('text', 'nameTextField', '98%');
    }
}

//PARAMETER STUFF******************************************************************************************************************************

function getEDRFields($row) {
    if ($row) {
        $acronym = $row['acronym'];
        $fullName = $row['name'];
        $country = $row['country'];
        $spaceAgencyID = $row['spaceAgencyID'];
        getHiddenField('spaceAgencyID', $spaceAgencyID);
    }
    $output .= 'Platform <br>';
    if ($row) {
        getFormInputElement('text', 'nameTextField', '98%', $fullName);
    } else {
        getGenericDropdownMenu(getSatellites2(), "platformDropdown", "98%", false, "getSensorsFromSat(this.value)", "platformDropdown");
    }
    $output .= '<br><br>';
    $output .= 'Sensor <br>';
    if ($row) {
        getFormInputElement('text', 'countryTextField', '98%', $country);
    } else {
        $output .= '<div id="sensorsBox"></div>';
    }
    $output .= '<br>';
    $output .= 'Parameter <br>';
    if ($row) {
        getFormInputElement('text', 'acronymTextField', '98%', $acronym);
    } else {
        getGenericDropdownMenu(getParameters(), 'parameterDropdown', '98%', false, NULL, 'parameterDropdown');
    }
    $output .= '<br><br>';
    $output .= 'Measuring Relevance <br>';
    if ($row) {
        getFormInputElement('text', 'acronymTextField', '98%', $acronym);
    } else {
        getGenericDropdownMenu(getMeasuringRelevance(), 'relevanceDropdown', '98%', false, NULL, 'relevanceDropdown');
    }
    $output .= '<br><br>';
    $output .= 'Limitation <br>';
    if ($row) {
        getFormInputElement('text', 'limitationTextField', '98%');
    } else {
        getFormInputElement('text', 'limitationTextField', '98%', NULL, NULL, 'limitationTextField');
    }
    $output .= '<br><br>';
    getFormInputElement('button', 'addEdrToListButton', "98%", "Add EDR to list", "addEDRRow()");
}

function getEDRForm($result = NULL) {
    $row = NULL;
    if ($result) {
        $row = mysqli_fetch_array($result);
    }
    getFormLinePostWithOnSubmit("satelliteForm", "editDBSubmit.php", "validateEDR(this)");
    $output .= '<table class="width40Center" cellspacing="1">';
    if ($row) {
        $output .= '<caption>Edit EDR</caption>';
    } else {
        $output .= '<caption>Create EDR</caption>';
    }
    $output .= ' <tr class ="fieldLabel">';
    $output .= '     <td class="category">';
    $output .= '        EDR Information';
    $output .= '     </td>';
    $output .= '     <td class="category">';
    $output .= '        EDR Submission List';
    $output .= '     </td>';
    $output .= ' </tr>';

    //divs
    $output .= ' <tr>';
    $output .= '     <td class ="fieldLabel">';
    $output .= '        <div class="container350px" id="edrInfoBox">';
    getEDRFields($row);
    $output .= '        </div>';
    $output .= '     </td>';
    $output .= '     <td class ="fieldLabel">';
    $output .= '        <div class="container350px" id="edrSubmitBox">';
    $output .= '<table class="width40Center" cellspacing="1" id="edrSubmitTable">';

    $output .= '</table>';
    //$output .= ''edrSubmitTable
    $output .= '        </div>';
    $output .= '     </td>';
    $output .= ' </tr>';
    $output .= ' <tr>';
    $output .= '     <td class ="fieldLabel" colspan="2">';
    if ($row) {
        getFormInputElement('submit', 'submit', NULL, "Update EDR");
        $agencyID = $row['spaceAgencyID'];
        getHiddenField('spaceAgencyID', $agencyID);
    } else {
        getFormInputElement('submit', 'submit', NULL, "Create EDR");
    }
    $output .= '     </td>';
    $output .= ' </tr>';
    getCloseTag("table");
    getCloseTag("form");
}

/**
 * Edit a parameter form
 * @param type $type
 */
function getParameterForm($result = NULL) {
    $row = NULL;
    if ($result) {
        $row = mysqli_fetch_array($result);
    }
    getFormLinePostWithOnSubmit("satelliteForm", "editDBSubmit.php", "validateParameter(this)");
    $output .= '<table class="width40Center" cellspacing="1">';
    if ($row) {
        $output .= '<caption>Edit Parameter</caption>';
    } else {
        $output .= '<caption>Create Parameter</caption>';
    }
    $output .= ' <tr class ="fieldLabel">';
    $output .= '     <td class="category">';
    $output .= '        Parameter Name';
    $output .= '     </td>';
    $output .= ' </tr>';
    $output .= '<tr>';
    $output .= '  <td>';
    if ($row) {
        $parameterName = $row['name'];
        getFormInputElement('text', 'parameterTextField', '98%', $parameterName);
        $parameterID = $row['parameterID'];
        getHiddenField("parameterID", $parameterID);
    } else {
        getFormInputElement('text', 'parameterTextField', '98%');
    }
    $output .= '  </td>';
    $output .= '</tr>';
    $output .= '<tr><td class="fieldLabel" colspan="3">';
    if ($row) {
        getFormInputElement("submit", "submit", NULL, "Update Parameter");
    } else {
        getFormInputElement("submit", "submit", NULL, "Create Parameter");
    }
    $output .= '</td></tr>';
    getCloseTag("table");
    getCloseTag("form");
}

/**
 * 
 * @param type $result The mysql result for the parameters table
 */
function getNewRequirementFormForDb2($result, $submissionType = NULL, $selectedItems = NULL) {
    $output = "";
    $output .= getFormLinePostWithOnSubmit("createReqForm", "editDBSubmit.php", "validateNewRequirement(this)");
    //getStartFormLinePost("createReqForm", "editDBSubmit.php");
//printResults($result);
//$output .= 'projectID: '.$projectID;
    $output .= '<table class="width75Center" cellspacing="1">';
    $output .= '<caption>Add Requirement</caption>';
    //$output .= '<col width="25%"><col width="25%"><col width="25%"><col width="25%">';
    $output .= ' <tr class ="fieldLabel">';
    $output .= '     <td class="category">';
    $output .= '        Requirement Description';
    $output .= '     </td>';
    $output .= '     <td class="category">';
    $output .= '        Source';
    $output .= '     </td>';
    $output .= '     <td class="category">';
    $output .= '        Fiscal Year';
    $output .= '     </td>';
    $output .= ' </tr>';
    $output .= ' <tr class ="fieldLabel">';
    $output .= '     <td class="col-2">';
    if (strcmp("edit", $submissionType) === 0) {
        
    } else {
        $output .= getFormInputElement("text", "textfieldReq", "98%", NULL, NULL, NULL, NULL, "The name or description of the requirement");
    }
    $output .= '     </td>';
//    $output .= '     <td class="col-2">';
//    getGenericDropdownMenu(getDistinctEdrDescriptions(), "dropdownParameter");
//    $output .= '     </td>';
    $output .= '     <td class="col-2">';
    $output .= getFormInputElement("text", "textfieldSource", "98%", NULL, NULL, NULL, NULL, "The source this requirement originates from");
    $output .= '     </td>';
    $output .= '     <td class="col-2">';
    //$output .= getFormInputElement("text", "textfieldPriority", "98%");
    $output .= getDropDownMenu(getFiscalYearArray(), "fyDropdown", NULL, "The FY this requirement applies to");
    //$array = array("1=high", "2=med", "3=low");
    //$output .= getDropDownMenu($array, "dropdownPriority");
    $output .= '     </td>';
    $output .= ' </tr>';
//    $output .= ' <tr class ="fieldLabel">
//               <td colspan="3">Select applicable parameter(s)</td>';
//
//    $output .= ' </tr>';
    //comment for now
//    $output .= ' <tr>
//               <td colspan="3" class="col-2">
//                  <div class="container">';
//    $counter = 0;
//    while ($row = mysqli_fetch_array($result)) {
//        $parameterID = $row['parameterID'];
//        $parameterName = getParameterNameFromID($parameterID);
//        $name = $row['name'];
//        $priority = $row['priority'];
//        $output .= "<input name =\"checkbox$counter\" id =\"checkbox$counter\" value = \"$parameterID\"type=\"checkbox\"/>$parameterName<br />";
//        $counter++;
//    }
//    $output .= ' </tr>';
    $output .= ' <tr class ="fieldLabel">';
    $output .= '     <td colspan="1">';
    $output .= getFormInputElement("submit", "submit", NULL, "Submit New Requirement");
    $output .= '     </td>';
    $output .= '     <td colspan="2">';
    $output .= '     </td>';
    $output .= ' </tr>';
    $output .= getCloseTag("table");
    $output .= getCloseTag("form");
    return $output;
}

/**
 * Returns a skeleton requirements form with a fiscal year dropdown
 */
function getEditRequirementFormForDb() {
    $output = "";
    $output .= getFormLinePostWithOnSubmit("editReqForm", "editDBSubmit.php", "validateEditRequirement(this)");
    $output .= '<table class="width75Center" cellspacing="1">';
    $output .= '<caption>Edit Requirement</caption>';
    $output .= ' <tr class ="fieldLabel">';
    $output .= '     <td class="category">Requirement Description</td>';
//  $output .= '     <td class="category">Parameter(s)</td>';
    $output .= '     <td class="category">Other</td>';
    $output .= ' </tr>';
    $output .= ' <tr class ="fieldLabel">';
    $output .= '     <td class="col-2">';
    $output .= '        <div class="container700px">';
    $result = getValidRequirementYears();
    $output .= ' Fiscal Year <br>';
    $output .= getGenericDropdownMenu($result, "fiscalYearDropdown", NULL, true, "refreshReq(this.value)", NULL, NULL, NULL, "Select a FY to view requirements");
//    $output .= getFormInputElement("radio", "group1", NULL, "All", "refreshReq(this.value)", NULL, "checked");
//    $output .= 'All   ';
//    $output .= getFormInputElement("radio", "group1", NULL, "Active", "refreshReq(this.value)");
//    $output .= 'Active   ';
//    $output .= getFormInputElement("radio", "group1", NULL, "Inactive", "refreshReq(this.value)");
    //   $output .= 'Inactive</br></br>';
    $output .= '          <div id="reqBox"><br>';
    $output .= '          </div>';
    $output .= '       </div>';
    $output .= '     </td>';
//    $output .= '     <td class="col-2" >';
//    $output .= '        <div class="container300pxScrolls">';
//    $output .= '           <div id="edrBox"></div>';
//    $output .= '        </div>';
//    $output .= '     </td>';
    $output .= '     <td class="col-2" >';
    $output .= '        <div class="container2">';
    //$output .= '            Source';
    $output .= '           <div id="sourceBox"></div></br>';
    //$output .= '            Priority';
    $output .= '           <div id="priorityBox"></div></br>';
    //$output .= '            Active';
    $output .= '           <div id="activeBox"></div></br>';
    $output .= '        </div>';
    $output .= '     </td>';
    $output .= ' </tr>';
    $output .= ' <tr class ="fieldLabel">';
    $output .= '     <td>';
    $output .= getFormInputElement("submit", "submit", NULL, "Update Requirement");
    $output .= '     </td>';
    $output .= '     <td>';
    //$output .= getFormInputElement("submit", "submit", NULL, "Delete Requirement");
    $output .= '     </td>';
    $output .= '     <td colspan="1">';
    $output .= '     </td>';
    $output .= ' </tr>';
    $output .= getCloseTag("table");
    $output .= getCloseTag("form");
    return $output;
}

/**
 * Returns a skeleton requirements priority form with a fiscal year dropdown
 */
function getEditRequirementPriorityForm() {
    $output = "";
    $output .= getFormLinePost("editReqForm", "editDBSubmit.php");
//printResults($result);
//$output .= 'projectID: '.$projectID;
    $output .= '<table class="width40Center" cellspacing="1">';
    $output .= '<caption>Edit Requirement Priorities</caption>';
    //$output .= '<col width="25%"><col width="25%"><col width="25%"><col width="25%">';
    $output .= ' <tr class ="fieldLabel">';
    $output .= '     <td class="category">';
    $output .= '        Requirement Description';
    $output .= '     </td>';
    $output .= ' </tr>';

    $output .= '<tr class ="fieldLabel">';
    $output .= '<td class="col-2">';
    $result = getValidRequirementYears();
    $output .= ' Fiscal Year <br>';
    $output .= getGenericDropdownMenu($result, "fiscalYearDropdown", NULL, true, "refreshReq2(this.value)", NULL, NULL, NULL, "Select a FY to view requirements");
    $output .= '<div id="reqBox2"></div>';
    //$result = executeSelect("SELECT * FROM requirement ORDER by priority");
    //getReqListBox($result);
    $output .= '</td></tr>';
    $output .= getCloseTag("table");
    $output .= getCloseTag("form");
    return $output;
}

/**
 * Updates the edr-->sat-->sensor relationships according to a csv file
 */
function getEditTablesForm() {

    $output = getFormLinePost("editDBForm", "editDBSubmit.php");
    //printResults($result);
    //$output .= 'projectID: '.$projectID;
    $output .= '<table class="width100" cellspacing="1">';
    $output .= '<caption>Edit Database</caption>';
    $output .= ' <tr class ="fieldLabel">';
    $output .= '     <td colspan="3">';
    $output .= getFormInputElement("submit", "submit", NULL, "Update sensor sat edr");
    $output .= '     </td>';
    $output .= ' </tr>';
    $output .= ' <tr class ="fieldLabel">';
    $output .= '     <td colspan="3">';
    $output .= getFormInputElement("submit", "submit", NULL, "Clear Database");
    $output .= '     </td>';
    $output .= ' </tr>';
    $output .= ' <tr class ="fieldLabel">';
    $output .= '     <td colspan="3">';
    $output .= getFormInputElement("submit", "submit", NULL, "Clear Projects");
    $output .= '     </td>';
    $output .= ' </tr>';
    $output .= ' <tr class ="fieldLabel">';
    $output .= '     <td>Select a Project</td>';
    $output .= '     <td>';
    $output .= getGenericDropdownMenu(executeSelect("SELECT projectId,title FROM project"), "dropdownProject", "100%", false);
    $output .= '     </td>';
    $output .= '     <td>';
    $output .= getFormInputElement("submit", "submit", NULL, "Delete");
    $output .= '     </td>';
    $output .= ' </tr>';
    $output .= getCloseTag("table");
    $output .= getCloseTag("form");
    return $output;
}

/**
 * Returns the html form which displays the num of rows in some tables along with the ability
 * to update the edr-->sat-->sensor relationships
 */
function getTableNumRowsForm() {
    $tdClass = "category3";
    $output = getFormLinePost("createReqForm", "editDBSubmit.php");
    $output .= '<table class="width100" cellspacing="1">';
    $output .= '<caption>Num Rows</caption>';
    $output .= ' <tr class ="fieldLabel">';
    $output .= '     <td class=' . $tdClass . '>';
    $output .= '        Sensor:';
    $output .= '     </td>';
    $output .= '     <td class=' . $tdClass . '>';
    $output .= getNumberOfRows("sensor");
    $output .= '     </td>';
    $output .= '     <td class=' . $tdClass . '>';
    $output .= '        Satellite:';
    $output .= '     </td>';
    $output .= '     <td class=' . $tdClass . '>';
    $output .= getNumberOfRows("satellite");
    $output .= '     </td>';
    $output .= '     <td class=' . $tdClass . '>';
    $output .= '        Parameter:';
    $output .= '     </td>';
    $output .= '     <td class="' . $tdClass . '">';
    $output .= getNumberOfRows("parameter");
    $output .= '     </td>';
    $output .= '     <td class=' . $tdClass . '>';
    $output .= '        EDR:';
    $output .= '     </td>';
    $output .= '     <td class="' . $tdClass . '">';
    $output .= getNumberOfRows("edr");
    $output .= '     </td>';
    $output .= '     <td class=' . $tdClass . '>';
    $output .= '        WBS:';
    $output .= '     </td>';
    $output .= '     <td class="' . $tdClass . '">';
    $output .= getNumberOfRows("wbs");
    $output .= '     </td>';
    $output .= ' </tr>';
    $output .= ' <tr>';
    $output .= '     <td colspan="2" class="fieldLabel">';
    $output .= getFormInputElement("submit", "submit", NULL, 'updateSensors');
    $output .= '     </td>';
    $output .= '     <td colspan="2" class="fieldLabel">';
    $output .= getFormInputElement("submit", "submit", NULL, 'updateSatellites');
    $output .= '     </td>';
    $output .= '     <td colspan="2" class="fieldLabel">';
    $output .= getFormInputElement("submit", "submit", NULL, 'updateParameters');
    $output .= '     </td>';
    $output .= '     <td colspan="2" class="fieldLabel">';
    $output .= getFormInputElement("submit", "submit", NULL, 'updateEdrs');
    $output .= '     </td>';
    $output .= '     <td colspan="2" class="fieldLabel">';
    $output .= getFormInputElement("submit", "submit", NULL, 'updateWbs');
    $output .= '     </td>';
    $output .= ' </tr>';
    $output .= ' <tr class ="fieldLabel">';
    $output .= '     <td class=' . $tdClass . '>';
    $output .= '        Space Agency:';
    $output .= '     </td>';
    $output .= '     <td class=' . $tdClass . '>';
    $output .= getNumberOfRows("spaceagency");
    $output .= '     </td>';
    $output .= '     <td class=' . $tdClass . '>';
    $output .= '        Programme:';
    $output .= '     </td>';
    $output .= '     <td class=' . $tdClass . '>';
    $output .= getNumberOfRows("satelliteprogramme");
    $output .= '     </td>';
    $output .= '     <td class=' . $tdClass . ' colspan="6">';
    $output .= '     </td>';
    $output .= '</tr>';
    $output .= ' <tr>';
    $output .= '     <td colspan="2" class="fieldLabel">';
    $output .= getFormInputElement("submit", "submit", NULL, 'updateSpaceAgencies');
    $output .= '     </td>';
    $output .= '     <td colspan="2" class="fieldLabel">';
    $output .= getFormInputElement("submit", "submit", NULL, 'updateProgramme');
    $output .= '     </td>';
    $output .= '     <td colspan="7" class="fieldLabel">';
    $output .= '     </td>';
    $output .= '</tr>';
    $output .= ' <tr class ="fieldLabel">';
    $output .= '     <td class=' . $tdClass . '>';
    $output .= '        Task:';
    $output .= '     </td>';
    $output .= '     <td class=' . $tdClass . '>';
    $output .= getNumberOfRows("task");
    $output .= '     </td>';
    $output .= '     <td class=' . $tdClass . '>';
    $output .= '        Sub Task:';
    $output .= '     </td>';
    $output .= '     <td class=' . $tdClass . '>';
    $output .= getNumberOfRows("subtask");
    $output .= '     </td>';
    $output .= '     <td class=' . $tdClass . '>';
    $output .= '        Project:';
    $output .= '     </td>';
    $output .= '     <td class="' . $tdClass . '">';
    $output .= getNumberOfRows("project");
    $output .= '     </td>';
    $output .= '<td colspan="4" class ="' . $tdClass . '"></td>';
    $output .= ' </tr>';
    $output .= ' </tr>';
    $output .= ' <tr class ="fieldLabel">';
    $output .= ' </tr>';
    $output .= ' <tr>';
    $output .= ' </tr>';
    $output .= getCloseTag("table");
    $output .= getCloseTag("form");
    return $output;
}


/**
 * Returns a form with a projects dropdown
 */
function getProjectSelectForm($user = NULL, $caption = NULL) {
    $output .= '<div class="centered">';
    $output .= getFormLinePost("fySubmitForm", "charts.php");
    $output .= '<table  class="width20Center" cellspacing="1">';
    if ($caption) {
        $output .= '<caption>' . $caption . '</caption>';
    } else {
        $output .= '<caption>Select Project</caption>';
    }
    $output .= ' <tr class ="fieldLabel">';
    $output .= '     <td class="center">';
    if ($user) {
        $personID = getPersonIDFromUsername($user);
        //$output .= "User: $user PersonID: $personID";
        $projects = executeSelect("SELECT * FROM project p, projectpersonnel pp WHERE pp.personID=$personID AND p.projectID=pp.projectID");
    } else {
        $projects = getAllFieldsInTable("project");
    }
    //getTwoArgDropDown($projects, "projectDropdown");
    getGenericDropdownMenu($projects, "projectDropdown", NULL, false);
    $output .= '     </td>';
    $output .= ' </tr>';
    $output .= ' <tr class ="fieldLabel">';
    $output .= '     <td class="center">';
    $output .= getFormInputElement("submit", "submit", NULL, "Submit");
    $output .= '     </td>';
    $output .= ' </tr>';
    $output .= getCloseTag("table");
    $output .= getCloseTag("form");
    $output .= getCloseTag("div");
}

//GENERIC HTML STUFF************************************************************


function getUrlLink($wbsID) {
    $wbsString = getWbsString($wbsID);
    $numLevels = substr_count($wbsString, ".");
    if ($numLevels === 1) {
        $sqlResult = executeSelect("SELECT projectID FROM project WHERE wbsID='$wbsID'");
        $row = mysqli_fetch_array($sqlResult);
        $projectId = $row['projectID'];
        return "projectController.php?projectId=$projectId";
    } else if ($numLevels === 2) {
        $sqlResult = executeSelect("SELECT projectID, taskID FROM task WHERE wbsID='$wbsID'");
        $row = mysqli_fetch_array($sqlResult);
        $projectId = $row['projectID'];
        $taskId = $row['taskID'];
        return "taskController.php?projectId=$projectId&taskId=$taskId";
    } else if ($numLevels === 3) {
        $sqlSelect = "SELECT p.projectID, p.startDate, p.endDate, t.taskID, st.subtaskID 
                  FROM project p, task t, subtask st 
                  WHERE t.projectID=p.projectID AND t.taskID=st.taskID AND st.wbsID='$wbsID'";
        $subtaskResult = executeSelect($sqlSelect);
        //$output .= $sqlSelect;
        if ($subtaskResult) {
            $row = mysqli_fetch_array($subtaskResult);
            $projectId = $row['projectID'];
            $taskId = $row['taskID'];
            $subtaskId = $row['subtaskID'];
            $start = $row['startDate'];
            $end = $row['endDate'];
            return "subtaskController.php?projectId=$projectId&taskId=$taskId&subtaskId=$subtaskId&start=$start&end=$end";
        } else {
            $output .= 'Error getting subtask url <br>';
        }
    }
}

function getStatus($tableName, $id) {
    if (strcmp($tableName, "project") === 0) {
        $result = getAllFieldsInTableGiveAnID("project", "projectID", $id);
    } else if (strcmp($tableName, "task") === 0) {
        $result = getAllFieldsInTableGiveAnID("task", "taskID", $id);
    } else if (strcmp($tableName, "subtask") === 0) {
        $result = getAllFieldsInTableGiveAnID("subtask", "subtaskID", $id);
    }

    if ($result) {
        $row = mysqli_fetch_array($result);
        return $row['status'];
    } else {
        return "";
    }
}

/**
 * Gets 3 css files: Jquery, JqueryUI, and JQuery CSS
 */
function getDatepickerCSSFiles() {
    getJavascriptFileLine("http://code.jquery.com/jquery-1.9.1.js");
    getJavascriptFileLine("http://code.jquery.com/ui/1.10.3/jquery-ui.js");
    getCSSFileLine("http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css");
}

/**
 * Generic datepicker function. Returns scripts for each datepicker field in the given array.
 * @param type $datepickerNameArray If null returns 4 datepicker fields
 */
function getDatepickerScript($datepickerNameArray = NULL) {
    //iterate through the array of names
    if ($datepickerNameArray) {
        $output .= ' <script> $(function() { ';
        for ($i = 0; $i < sizeof($datepickerNameArray); $i++) {
            $curName = $datepickerNameArray[$i];
            $output .= "$( \"#$curName\" ).datepicker();";
        }
        $output .= '}); </script>';
    }
    //default
    else {
        $output .= ' <script> $(function() { 
                         $( "#datepicker0" ).datepicker(); 
                         $( "#datepicker1" ).datepicker(); 
                         $( "#datepicker2" ).datepicker(); 
                         $( "#datepicker3" ).datepicker();}); </script>';
    }
}

/**
 * Returns the datepicker js,css files and the scripts
 * @param type $datepickerNameArray
 */
function getDatepickerStuff($datepickerNameArray = NULL) {
    $output = "";
//    $output .= getCSSFileLine("http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css");
//    $output .= getJavascriptFileLine("http://code.jquery.com/jquery-1.9.1.js");
//    $output .= getJavascriptFileLine("http://code.jquery.com/ui/1.10.3/jquery-ui.js");
//    $output .= getCSSFileLine(getJQueryUI_CSS());
//    $output .= getJavascriptFileLine(getJQueryUI_JS());
//    $output .= getJavascriptFileLine(getJQueryJS());
//    $output .= getJavascriptFileLine("js/formValidation.js");
//    $output .= getJavascriptFileLine("js/addRowToTable.js");
    //iterate through the array of names
    if ($datepickerNameArray) {
        $output .= ' <script> $(function() { ';
        for ($i = 0; $i < sizeof($datepickerNameArray); $i++) {
            $curName = "#" + $datepickerNameArray[$i];
            $output .= "$( \"$curName\" ).datepicker();";
        }
        $output .= '}); </script>';
    }
    //default
    else {
        $output .= ' <script> $(
                         function() { 
                            $( "#datepicker0" ).datepicker();
                            $( "#datepicker0" ).attr( \'readOnly\' , \'true\' );
                            $( "#datepicker1" ).datepicker();
                            $( "#datepicker1" ).attr( \'readOnly\' , \'true\' );
                            $( "#datepicker2" ).datepicker(); 
                            $( "#datepicker2" ).attr( \'readOnly\' , \'true\' );
                            $( "#datepicker3" ).datepicker();
                            $( "#datepicker3" ).attr( \'readOnly\' , \'true\' );
                         }); 
                     
                     </script>';
    }
    return $output;
}

/**
 * Returns the js,css files and the scripts with a restriction of dates only between start and end
 * @param type $start min start date
 * @param type $end max end date
 * @param type $multipleMonths if true=show multiple months 
 */
function getSubtaskDatepicker($start = NULL, $end = NULL, $multipleMonths = NULL) {
    $output = getCSSFileLine("http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css");
    $output .= getJavascriptFileLine("http://code.jquery.com/jquery-1.9.1.js");
    $output .= getJavascriptFileLine("http://code.jquery.com/ui/1.10.3/jquery-ui.js");
    $output .= getJavascriptFileLine("js/formValidation.js");
    $output .= getJavascriptFileLine("js/addRowToTable.js");
    //input format is yyyy-mm-dd
    //echo $end .' ' . $start;
    if ($end && $start) {
        $vals = explode("-", $start);
        $minDate = "new Date($vals[0], $vals[1] - 1, $vals[2])";
        $vals = explode("-", $end);
        $endDate = "new Date($vals[0], $vals[1] - 1, $vals[2])";

        if ($multipleMonths) {
            $mm = 'numberOfMonths: [1,2], showButtonPanel: true';
        }
        $output .= ' <script> $(function() { 
                         $( "#from" ).datepicker({ minDate: ' . $minDate . ', maxDate: ' . $endDate . ', onClose: function(selectedDate) {                         
                            $( "#to" ).datepicker( "option", "minDate", selectedDate );}
                         });
                         $( "#from" ).attr( \'readOnly\' , \'true\' );
                         $( "#to" ).datepicker({ minDate: ' . $minDate . ', maxDate: ' . $endDate . ', 
                              onClose: function( selectedDate ) {
                                  $( "#from" ).datepicker( "option", "maxDate", selectedDate );}
                         });   
                          $( "#to" ).attr( \'readOnly\' , \'true\' );
                     }); </script>';
    } else {
        $output .= ' <script> $(function() { 
                         $( "#from" ).datepicker({  
                              onClose: function(selectedDate) {
                                  $( "#to" ).datepicker( "option", "minDate", selectedDate );}
                         }); 
                         $( "#to" ).datepicker({  
                              onClose: function( selectedDate ) {
                                  $( "#from" ).datepicker( "option", "maxDate", selectedDate );}
                         });                          
                     }); </script>';
    }
    return $output;
}

/**
 * Gets a hidden field
 * @param type $fieldName hidden field name
 * @param type $value value of the hidden field
 * @param type $id
 */
function getHiddenField($fieldName, $value, $id=NULL) {
    if($id){
        $id = "id=\"$id\"";
    }
    return '      <input type="hidden" name="' . $fieldName . '" value="' . $value . '" '.$id.'>';
}

function getHiddenFieldText($fieldName, $value) {
    return '      <input type="hidden" name="' . $fieldName . '" value="' . $value . '">';
}

/**
 * Returns the html from <html> up to after the <meta> tag
 */
function getNewHtmlUpToMeta() {
    return '<!DOCTYPE html><html lang="en-us" xml:lang="en-us" dir="ltr" xmlns="http://www.w3.org/1999/xhtml"><head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">';
}

/**
 * Adds a js reference for the given path <script> tags included
 * @param type $sourcePath
 */
function getJavascriptFileLine($sourcePath) {
    return "<script type=\"text/javascript\" src=\"$sourcePath\"></script>";
}

/**
 * adds the css fileline to the html page given the css filepath
 * @param type $cssFilepath
 */
function getCSSFileLine($cssFilepath) {
    return '<link rel="stylesheet" type="text/css" href="' . $cssFilepath . '" />';
}

/**
 * Adds the css file used by mantis
 */
function getMantisCSSLine() {
    return '<link rel="stylesheet" type="text/css" href="css/default.css" />';
}

/**
 * Returns the html for the given title
 * @param type $title
 */
function getTitle($title) {
    return '<title>' . $title . '</title>';
}

/**
 * If js is enabled then it redirects to the given page --> probably a page that uses js
 * @param type $url
 */
function getJavascriptRedirect($url) {
    return '<script type="text/javascript">window.location = "' . $url . '"</script>';
}

/**
 * Returns the html up to the main menu for the given role
 * @param type $role
 * @param type $title
 */
function getUpToMainMenu($role, $title) {
    $output = "";
    $output .= getNewHtmlUpToMeta();
    $output .= getMantisCSSLine();
    $output .= getTitle($title);
    $output .= getCloseTag("head");
    $output .= getOpenTag("body");
    $output .= getLogoLine();
    $output .= getLoggedInAsLine();
    if (strcmp($role, "pi") === 0) {
        $output .= getPiMenu();
    } else if (strcmp($role, "admin") === 0) {
        $output .= getAdminMenu();
    } else if (strcmp($role, "pireviewer") === 0) {
        $output .= getPiReviewerMenu();
    } else if (strcmp($role, "piapprover") === 0) {
        $output .= getPiApproverMenu();
    } else if (strcmp($role, "cnmocUser") === 0) {
        $output .= getCnmocUserMenu();
    }
    return $output;
}

/**
 * Returns the top menu bar depending on the given role
 * @param type $role
 */
function getMenuBar($role) {
    if (strcmp($role, "pi") === 0) {
        return getPiMenu();
    } else if (strcmp($role, "admin") === 0) {
        return getAdminMenu();
    } else if (strcmp($role, "pireviewer") === 0) {
        return getPiReviewerMenu();
    } else if (strcmp($role, "piapprover") === 0) {
        return getPiApproverMenu();
    } else if (strcmp($role, "cnmocUser") === 0) {
        return getCnmocUserMenu();
    }
}

/**
 * Returns the html up to the main menu for the given role with a js redirect line in the html page
 * @param type $role
 * @param type $title
 * @param type $redirectUrl
 */
function getUpToMainMenuWithRedirect($role, $title, $redirectUrl) {
    getNewHtmlUpToMeta();
    getJavascriptRedirect($redirectUrl);
    getMantisCSSLine();
    getTitle($title);
    getCloseTag("head");
    getOpenTag("body");
    getLogoLine();
    if (strcmp($role, "pi") == 0) {
        getPiMenu();
    } else if (strcmp($role, "admin")) {
        getAdminMenu();
    }
}

/**
 * Returns html for a dropdown given an input array 
 * @param type $arrayVals an array of strings which will populate the array
 * @param type $dropdownName name of the dropdown
 * @param type $selectedItem name of the item selected (used when editing)
 * @param type $tooltip tip displayed when mouse hover
 * @param type $action js function to fire when a item is selected
 * @param type $id the id
 */
function getDropDownMenu($arrayVals, $dropdownName, $selectedItem = NULL, $tooltip = NULL, $action = NULL, $id = NULL) {
    $output = "";
    if ($tooltip) {
        $tooltip = "title = \"$tooltip\"";
    }
    if ($action) {
        $action = 'onchange="' . $action . '"';
    }
    if ($id) {
        $id = 'id="' . $id . '"';
    }
    $output .= '<select name="' . $dropdownName . '" ' . $tooltip . ' ' . $action . ' ' . $id . '>';
    $output .= '<option value=defaultSelection>(Select)</option>';
    if ($arrayVals && isset($arrayVals[0])) {
        for ($i = 0; $i < sizeof($arrayVals); $i++) {
            if (strcmp($arrayVals[$i], $selectedItem) == 0) {
                $output .= '<option selected value = "' . $arrayVals[$i] . '">' . $arrayVals[$i] . '</option>';
            } else {
                $output .= '<option value="' . $arrayVals[$i] . '">' . $arrayVals[$i] . '</option>';
            }
        }
    }
    //key/value array
    else {
        foreach ($arrayVals as $key => $value) {
            //$output .= "$arrayVals[$key] $selectedItem <br>";
            if (strcmp($key, $selectedItem) === 0) {
                $output .= '<option selected value = "' . $key . '">' . $value . '</option>';
            } else {
                $output .= '<option value="' . $key . '">' . $value . '</option>';
            }
        }
    }

    $output .= '</select>';
    return $output;
}

/**
 * 
 * @param type $arrayVals
 * @param type $dropdownName
 * @param type $selectedItem
 * @param type $tooltip
 * @param string $action
 * @param string $id
 * @return string
 */
function getDropDownMenuText($arrayVals, $dropdownName, $selectedItem = NULL, $tooltip = NULL, $action = NULL, $id = NULL) {
    $output = "";
    if ($tooltip) {
        $tooltip = "title = \"$tooltip\"";
    }
    if ($action) {
        $action = 'onchange="' . $action . '"';
    }
    if ($id) {
        $id = 'id="' . $id . '"';
    }
    $output .= '<select name="' . $dropdownName . '" ' . $tooltip . ' ' . $action . ' ' . $id . '>';
    $output .= '<option value=defaultSelection>(Select)</option>';
    for ($i = 0; $i < sizeof($arrayVals); $i++) {
        if (strcmp($arrayVals[$i], $selectedItem) == 0) {
            $output .= '<option selected value = "' . $arrayVals[$i] . '">' . $arrayVals[$i] . '</option>';
        } else {
            $output .= '<option value="' . $arrayVals[$i] . '">' . $arrayVals[$i] . '</option>';
        }
    }
    $output .= '</select>';
    return $output;
}

/**
 * 
 * @param type $result
 * @param string $name
 * @param string $width
 * @param type $oneArg
 * @param string $action
 * @param string $id
 * @param type $selectedItem
 * @param size $size
 * @param toolTip $toolTip
 */
function getGenericDropdownMenu($result, $name, $width = NULL, $oneArg = true, $action = NULL, $id = NULL, $selectedItem = NULL, $size = NULL, $toolTip = NULL) {

    $name = 'name="' . $name . '" ';

    if ($width) {
        $width = 'style="width:' . $width . ';" ';
    }
    if ($action) {
        $action = 'onchange="' . $action . '"';
    }
    if ($id) {
        $id = 'id="' . $id . '"';
    }
    if ($size) {
        $size = 'size="10"';
    }
    if ($toolTip) {
        $toolTip = "title=\"$toolTip\"";
    }
    $output = "";
    $output .= '<select ' . $name . ' ' . $action . ' ' . $id . ' ' . $size . ' ' . $toolTip . '>';
    $output .= '<option value = defaultSelection>(Select)</option>';
    while ($row = mysqli_fetch_row($result)) {
        if (strcmp($row[0], $selectedItem) == 0) {
            if ($oneArg) {
                $output .= '<option selected value = "' . $row[0] . '">' . $row[0] . '</option>';
            } else {
                $output .= '<option selected value = "' . $row[0] . '">' . $row[1] . '</option>';
            }
        } else {
            if ($oneArg) {
                $output .= '<option value = "' . $row[0] . '">' . $row[0] . '</option>';
            } else {
                $output .= '<option value = "' . $row[0] . '">' . $row[1] . '</option>';
            }
        }
    }
    $output .= '</select>';
    return $output;
}

/**
 * 
 * @param type $result
 * @param string $name
 * @param string $width
 * @param type $oneArg
 * @param string $action
 * @param string $id
 * @param type $selectedItem
 * @param string $size
 * @param type $toolTip
 * @param type $concat
 * @return string
 */
function getGenericDropdownMenuText($result, $name, $width = NULL, $oneArg = true, $action = NULL, $id = NULL, $selectedItem = NULL, $size = NULL, $toolTip = NULL, $concat = NULL) {

    $output = "";
    $name = 'name="' . $name . '" ';

    if ($width) {
        $width = 'style="width:' . $width . ';" ';
    }
    if ($action) {
        $action = 'onchange="' . $action . '"';
    }
    if ($id) {
        $id = 'id="' . $id . '"';
    }
    if ($size) {
        $size = 'size="10"';
    }
    if ($toolTip) {
        $toolTip = "title=\"$toolTip\"";
    }
    $output .= '<select ' . $name . ' ' . $action . ' ' . $id . ' ' . $size . ' ' . $toolTip . '>';
    $output .= '<option value = defaultSelection>(Select)</option>';
    while ($row = mysqli_fetch_row($result)) {
        if (strcmp($row[0], $selectedItem) == 0) {
            if ($oneArg) {
                $output .= '<option selected value = "' . $row[0] . '">' . $row[0] . '</option>';
            } else {
                if ($concat) {
                    $output .= '<option selected value = "' . $row[0] . '">' . $row[1] . ' (' . $row[2] . ')</option>';
                } else {
                    $output .= '<option selected value = "' . $row[0] . '">' . $row[1] . '</option>';
                }
            }
        } else {
            if ($oneArg) {
                $output .= '<option value = "' . $row[0] . '">' . $row[0] . '</option>';
            } else {
                if ($concat) {
                    $output .= '<option value = "' . $row[0] . '">' . $row[1] . ' (' . $row[2] . ')</option>';
                } else {
                    $output .= '<option value = "' . $row[0] . '">' . $row[1] . '</option>';
                }
            }
        }
    }
    $output .= '</select>';
    return $output;
}

function getDropDownWithSelection($arrayVals, $dropdownName, $selectedItem) {
    $output = "";
    $output .= '<select name = "' . $dropdownName . '">';
    $output .= '<option value = defaultSelection>(Select)</option>';
    for ($i = 0; $i < sizeof($arrayVals); $i++) {
        //$output .= 'array: ' . $arrayVals[$i] . ' selected: ' . $selectedItem . '<br>';
        if (strcmp($arrayVals[$i], $selectedItem) == 0) {
            $output .= '<option selected value = "' . $arrayVals[$i] . '">' . $arrayVals[$i] . '</option>';
        } else {
            $output .= '<option value = "' . $arrayVals[$i] . '">' . $arrayVals[$i] . '</option>';
        }
    }
    $output .= '</select>';
    return $output;
}

/**
 * Returns the html for the logoLine
 */
function getLogoLine() {
    return '<div align = "center"><h1>METOC Space Portfolio</h1></div><div align = "center"><a href = "mainPage.php"><img border = "0" alt = "Mantis Bug Tracker" src = "images/logo.jpg" /></a></div>';
}

/**
 * Returns the html for a main menu given the PI role
 */
function getPiMenu() {
    $output = "";
    $output .= '<table class = "width100" cellspacing = "0">';
    $output .= '<tr>';
    $output .= '<td class="menu">';
    $output .= getAnchorTag("Main", true);
    $output .= getAnchorTag("My Projects", true);
    $output .= getAnchorTag("Propose Project", true);
    $output .= getAnchorTag("Profile", true);
    $output .= getAnchorTag("Help", true);
    $output .= getAnchorTag("Logout", false);
    $output .= '</td>';
    $output .= '</tr>';
    $output .= '</table>';
    return $output;
}

function getPiReviewerMenu() {
    $output = "";
    $output .= '<table class = "width100" cellspacing = "0">';
    $output .= '<tr>';
    $output .= '<td class = "menu">';
    $output .= getAnchorTag("Main", true);
    //$output .= getAnchorTag("My Projects", true);
    $output .= getAnchorTag("View Projects", true);
    $output .= getAnchorTag("View Proposals", true);
    $output .= getAnchorTag("Profile", true);
    $output .= getAnchorTag("Help", true);
    $output .= getAnchorTag("Logout", false);
    $output .= '</td>';
    $output .= '</tr>';
    $output .= '</table>';
    return $output;
}

function getPiApproverMenu() {
    $output = "";
    $output .= '<table class = "width100" cellspacing = "0">';
    $output .= '<tr>';
    $output .= '<td class = "menu">';
    $output .= getAnchorTag("Main", true);
    $output .= getAnchorTag("View Portfolio", true);
    $output .= getAnchorTag("Funding Allocation", true);
    $output .= getAnchorTag("Approve/Disapprove Proposals", true);
    $output .= getAnchorTag("Profile", true);
    $output .= getAnchorTag("Help", true);
    $output .= getAnchorTag("Logout", false);
    $output .= '</td>';
    $output .= '</tr>';
    $output .= '</table>';
    return $output;
}

function getCnmocUserMenu() {
    $output = "";
    $output .= '<table class = "width100" cellspacing = "0">';
    $output .= '<tr>';
    $output .= '<td class = "menu">';
    $output .= getAnchorTag("Main", true);
    $output .= getAnchorTag("Requirements Maintenance", true);
    $output .= getAnchorTag("Sat/Sensor/Parameter/EDR Maintenance", true);
    $output .= getAnchorTag("Profile", true);
    $output .= getAnchorTag("Logout", false);
    $output .= '</td>';
    $output .= '</tr>';
    $output .= '</table>';
    return $output;
}

/**
 * Returns the html for a main menu given the ADMIN role
 */
function getAdminMenu() {
    $output = "";
    $output .= '<table class = "width100" cellspacing = "0">';
    $output .= '<tr>';
    $output .= '<td class = "menu">';
    $output .= getAnchorTag("Main", true);
    $output .= getAnchorTag("Edit Database", true);
    $output .= getAnchorTag("Requirements Maintenance", true);
    $output .= getAnchorTag("Sat/Sensor/Parameter/EDR Maintenance", true);
    $output .= getAnchorTag("Profile", true);
    $output .= getAnchorTag("Logout", false);
    $output .= '</td>';
    $output .= '</tr>';
    $output .= '</table>';
    return $output;
}

/**
 * gets a generic text area with the parameters specified in the default.css
 * @param type $name name of the textArea
 * @param type $maxLength maximum characters allowed for this textArea
 * @param type $value populated the textArea with this value
 * @param type $height height in pixels
 * @param type $other anything additional
 * 
 */
function getTextArea($name, $maxLength = NULL, $value = NULL, $height = NULL, $other=NULL) {
    $output = "";
    if ($maxLength) {
        $maxLength = "maxlength=\"$maxLength\"";
    }
    if($height){
        $height = 'style= "height:'.$height.'px"';
    }
    $output .= "<textarea name='$name' $maxLength $height $other>$value";
    $output .= "</textarea>";
    return $output;
}

/**
 * 
 * @param string $type
 * @param string $name
 * @param string $width
 * @param string $value
 * @param string $action
 * @param string $id
 * @param string $other can be used for checkboxes and radio buttons with "checked" passed in
 * @param string $tooltip
 */
function getFormInputElement($type, $name, $width = NULL, $value = NULL, $action = NULL, $id = NULL, $other = NULL, $tooltip = NULL) {

    $type = 'type = "' . $type . '" ';
    $name = 'name = "' . $name . '" ';

    if ($width) {
        $width = 'style = "width:' . $width . ';" ';
    } else {
        // $width = 'style = "width:99%;" ';
    }
    if ($value || strlen($value)>0) {
        //echo $value.'<br>';
        $value = 'value = "' . $value . '" ';
        //echo $value.'<br>';
        //return;
    }
    if ($action) {
        $action = 'onclick = "' . $action . '" ';
    }
    if ($id) {
        $id = 'id = "' . $id . '"';
    }
    if ($tooltip) {
        $tooltip = 'title = "' . $tooltip . '"';
    }
    return '<input ' . $type . ' ' . $name . ' ' . $width . ' ' . $value . ' ' . $action . ' ' . $id . ' ' . $other . ' ' . $tooltip . '>';
}

/**
 * 
 * @param string $type
 * @param string $name
 * @param string $width
 * @param string $value
 * @param string $action
 * @param string $id
 * @param type $other
 * @param string $tooltip
 * @return type
 */
function getFormInputElementText($type, $name, $width = NULL, $value = NULL, $action = NULL, $id = NULL, $other = NULL, $tooltip = NULL) {

    if ($width) {
        $width = 'style = "width:' . $width . ';" ';
    } else {
        // $width = 'style = "width:99%;" ';
    }
    if ($value) {
        $value = 'value = "' . $value . '" ';
    }
    if ($action) {
        if (strcmp($type, "text") === 0) {
            $action = 'onchange = "' . $action . '" ';
        } else {
            $action = 'onclick = "' . $action . '" ';
        }
    }
    if ($id) {
        $id = 'id = "' . $id . '"';
    }
    if ($tooltip) {
        $tooltip = 'title = "' . $tooltip . '"';
    }
    $type = 'type = "' . $type . '" ';
    $name = 'name = "' . $name . '" ';


    return '<input ' . $type . ' ' . $name . ' ' . $width . ' ' . $value . ' ' . $action . ' ' . $id . ' ' . $other . ' ' . $tooltip . '>';
}

/**
 * Gets the html to start a form using POST (pass in the formName and the php that fired upon submit)
 * @param type $formName
 * @param type $actionFilename
 * @param type $options anything else needed
 */
function getFormLinePost($formName, $actionFilename, $options = NULL) {
    return '<form name = "' . $formName . '" method = "POST" action = "' . $actionFilename . '" '.$options.'>';
}

/**
 * Gets the html to start a form using POST (pass in the formName and the php that fired upon submit)
 * @param type $formName
 * @param type $actionFilename what php file is called after form submission
 * @param type $onSubmit what function to call onSubmit (formValidation, etc)
 */
function getFormLinePostWithOnSubmit($formName, $actionFilename, $onSubmit) {
    return '<form name = "' . $formName . '" method = "POST" action = "' . $actionFilename . '" onsubmit = "return ' . $onSubmit . '">';
}

/**
 * Gets the html to start a form using GET (pass in the formName and the php that fired upon submit)
 * @param type $formName
 * @param type $actionFilename
 */
function getFormLineGet($formName, $actionFilename) {
    return '<form name = "' . $formName . '" method = "GET" action = "' . $actionFilename . '">';
}

function getProjectTitle($projectID) {
    $projectResult = executeSelect("SELECT * FROM project WHERE projectID=$projectID");
    $row = mysqli_fetch_array($projectResult);
    return $row['title'];
}

function getOpenTag($tagname) {
    return '<' . $tagname . '>';
}

function getCloseTag($tagname) {
    return '</' . $tagname . '>';
}

function getConfirmBoxScript() {
    return"<script>
          function myFunction(text)
          {
             return confirm(text);
          }
         </script>";
}

function getExpandCollapseAllScript() {
    return "<script type=\"text/javascript\"> 
    function ToggleList(IDS) {
      HideRange('ulist','div',IDS);  // not required unless using 'HideRange()' below
      var CState = document.getElementById(IDS);
      if (CState.style.display != \"block\") { 
         CState.style.display = \"block\"; 
      }
      else { CState.style.display = \"none\"; 
      }
    }
    function HideRange(sect,elTag,IDS) {
       var ContentObj = document.getElementById(sect);
       var AllContentDivs = ContentObj.getElementsByTagName(elTag);
       for (i=0; i<AllContentDivs.length; i++) {
          if (IDS !== AllContentDivs[i].id) { 
             AllContentDivs[i].style.display=\"none\"; 
          }
       }
    }
</script>";
}

function getExpandOneCollapseOneScript() {
    return "<script type=\"text/javascript\"> 
    function ToggleList(IDS) {
      var CState = document.getElementById(IDS);
      if (CState.style.display != \"block\") { 
         CState.style.display = \"block\"; 
      }
      else { CState.style.display = \"none\"; 
      }
    }
    function HideRange(sect,elTag,IDS) {
       var ContentObj = document.getElementById(sect);
       var AllContentDivs = ContentObj.getElementsByTagName(elTag);
       for (i=0; i<AllContentDivs.length; i++) {
          if (IDS !== AllContentDivs[i].id) { 
             AllContentDivs[i].style.display=\"none\"; 
          }
       }
    }
</script>";
}

?>
